﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace FeatureModelCore.FMShapes
{
    public class FMPoint : ICloneable
    {
        #region XML Symble
        public readonly static string _XML_POINT_X = "PointX";
        public readonly static string _XML_POINT_Y = "PointY";
        #endregion


        public double X { get; internal set; }
        public double Y { get; internal set; }

        public FMPoint()
        {
            X = -1;
            Y = -1;
        }

        public FMPoint(double x, double y)
        {
            X = x;
            Y = y;
        }

        public FMPoint(FMPoint point)
        {
            X = point.X;
            Y = point.Y;
        }

        #region XML Parser
        /// <summary>
        /// Add ponit attribute in curren element
        /// </summary>
        /// <param name="xelem"></param>
        public void ToXElem(XElement xelem)
        {
            xelem.Add(new XAttribute(_XML_POINT_X, X));
            xelem.Add(new XAttribute(_XML_POINT_Y, Y));
        }
        /// <summary>
        /// Parse xelement
        /// </summary>
        /// <param name="xelem"></param>
        public static FMPoint ParseXElem(XElement xelem)
        {
            XAttribute xX = xelem.Attribute(_XML_POINT_X);
            XAttribute xY = xelem.Attribute(_XML_POINT_Y);
            double x = -1, y = -1;
            if (xX != null)
            {
                x = double.Parse(xX.Value);
                y = double.Parse(xY.Value);
            }
            return new FMPoint(x, y);
        }
        #endregion

        public object Clone()
        {
            return new FMPoint(X, Y);
        }
    }
}
